<html>
<head>
<title>Hello Ajax version 5a</title>
<style type='text/css'>
* { font-family: Tahoma, Arial, sans-serif; }
#helloTitle{ color: #48f; }
.sidebar{
  background-color: #adf;
  color: navy;
  border: solid blue 1px;
  width: 180px;
  height: 200px;
  padding: 2px;
  margin: 3px;
  float: left;
}
</style>
<script type='text/javascript' src='../../js/prototype/prototype.js'></script>
<script type='text/javascript' src='../../js/prototype/json2.js'></script>
<script type='text/javascript'>
window.onload=function(){
  $('helloBtn').onclick=function(){
    var name=$('helloTxt').value;
    new Ajax.Request(
      "hello5a.jsp",
      {
//         method: 'get',
    	postBody:JSON.stringify({name:name}),  //point***
        onComplete:function(xhr){
          var responseObj=JSON.parse(xhr.responseText);  //point****
          update(responseObj);
        }
      }
    );
  }
}

function update(obj){
  $('helloTitle').innerHTML="<h1>Hello, <b><i>"+obj.name+"</i></b></h1>";
  var likesHTML='<h5>'+obj.initial+' likes...</h5><hr/>';
  for (var i=0;i<obj.likes.length;i++){
    likesHTML+=obj.likes[i]+"<br/>";
  }
  $('likesList').innerHTML=likesHTML;
  var recipeHTML='<h5>'+obj.initial+'\'s favourite recipe</h5>';
  for (key in obj.ingredients){
    recipeHTML+=key+" : "+obj.ingredients[key]+"<br/>";
  }
  $('ingrList').innerHTML=recipeHTML;
}

</script>
</head>
<body>

<div id='likesList' class='sidebar'>
<h5>Likes</h5><hr/>
</div>
<div id='ingrList' class='sidebar'>
<h5>Ingredients</h5><hr/>
</div>
<div>
<div id='helloTitle'>
<h1>Hello, stranger</h1>
</div>
<p>Please introduce yourself by entering your name in the box below</p>
<input type='text' size='24' id='helloTxt'></input>&nbsp;<button id='helloBtn'>Submit</button>
</body>
</div>
</html>